package com.example.dmc_android_sellbreakfast_ver1;

import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.content.ClipData.Item;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.Toast;

public class TabhostActivity extends Activity {
	private TabHost mTabHost;
	static Adapter mAdapter_fastfood, mAdapter_drink, mAdapter_food;
	ListView lv_fastfood, lv_food, lv_drink;
	ArrayList<foods> list_fastfood, list_drink, list_food;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_tabhost);
		getActionBar().setDisplayShowTitleEnabled(false);
		getActionBar().setDisplayUseLogoEnabled(false);

		init();
		handle();
	}

	private void init() {
		// TODO Auto-generated method stub
		tabhost();
		lv_fastfood = (ListView) findViewById(R.id.lv_fastfood);
		lv_drink = (ListView) findViewById(R.id.lv_drinks);
		lv_food = (ListView) findViewById(R.id.lv_food);
		list_fastfood = new ArrayList<foods>();
		list_drink = new ArrayList<foods>();
		list_food = new ArrayList<foods>();
		foods fastfood1 = new foods("Snack tom", "5000", R.drawable.strawberry);
		foods fastfood2 = new foods("Snack Oishi", "5000",R.drawable.snackoishi);

		list_fastfood.add(fastfood1);
		list_fastfood.add(fastfood2);

		foods food1 = new foods("Noodle", "1000", R.drawable.noodle);
		foods food2 = new foods("My Quang", "10000", R.drawable.myquang);
		foods food3 = new foods("Bun bo Hue", "10000", R.drawable.bunbohue);
		foods food4 = new foods("Xoi", "5000", R.drawable.xoi);
		list_food.add(food1);
		list_food.add(food2);
		list_food.add(food3);
		list_food.add(food4);

		foods drink1 = new foods("Sprite", "10000", R.drawable.sprite);
		foods drink2 = new foods("Coca Cola", "9000", R.drawable.cocacola);
		foods drink3 = new foods("Pepsi", "7000", R.drawable.pepsi);
		foods drink4 = new foods("Coffee", "7000", R.drawable.coffee);

		list_drink.add(drink1);
		list_drink.add(drink2);
		list_drink.add(drink3);
		list_drink.add(drink4);

		mAdapter_fastfood = new Adapter(this, list_fastfood);
		mAdapter_drink = new Adapter(this, list_drink);
		mAdapter_food = new Adapter(this, list_food);
		lv_fastfood.setAdapter(mAdapter_fastfood);
		lv_drink.setAdapter(mAdapter_drink);
		lv_food.setAdapter(mAdapter_food);
	}

	public void tabhost() {
		mTabHost = (TabHost) findViewById(R.id.tabhost);
		mTabHost.setup();
		mTabHost.addTab(mTabHost
				.newTabSpec("list 1")
				.setIndicator("FastFood",
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.item_tab_fastfood));
		mTabHost.addTab(mTabHost
				.newTabSpec("list 2")
				.setIndicator("Drink",
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.item_tab_drink));
		mTabHost.addTab(mTabHost
				.newTabSpec("list 3")
				.setIndicator("Food",
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.item_tab_food));
	}

	private void handle() {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.action_bar, menu);
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.itProfile:
			Intent mIntent = new Intent(this, ShowInfoActivity.class);
			Bundle data_recive = getIntent().getExtras();
			String id_user = null,
			pw_user = null;
			if (data_recive != null) {
				id_user = data_recive.getString("id_user");
				pw_user = data_recive.getString("pw_user");
				Toast.makeText(this,
						"da goi dc buoc 1" + id_user + "\n" + pw_user, 1000)
						.show();
			}
			mIntent.putExtra("id_user", id_user);
			mIntent.putExtra("pw_user", pw_user);
			startActivity(mIntent);
			return true;
		case R.id.itBack:
			onBackPressed();
			return true;
		case R.id.itBill:
			//if (mAdapter_food != null) {
			//	for (foods food : mAdapter_food.mArrayList) {
			//		String a = "Name " + food.getName() + " Cost "+ food.getCost() + " Cout" + food.getCout();
			//	}
			//}
			Intent intent1 = new Intent(this, ShowBillActivity.class);
			Bundle data_recive1 = getIntent().getExtras();
			String id_user1 = null,
			pw_user1 = null;
			if (data_recive1 != null) {
				id_user1 = data_recive1.getString("id_user");
				pw_user1 = data_recive1.getString("pw_user");
			}
			intent1.putExtra("id_user", id_user1);
			intent1.putExtra("pw_user", pw_user1);
			startActivity(intent1);
			return true;
		case R.id.itLogout:
			Intent mIntent2 = new Intent(this, MainActivity.class);
			startActivity(mIntent2);
			return true;
		}
		return false;
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub

		super.onBackPressed();
	}

}
